package com.itheima.common;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 基于ThreadLocal封装工具类，用户保存和获取当前登录用户id
 *
 * @author tongdulong@itcas.cn
 */
@Component
public class TokenHolder {
    private static final ThreadLocal<String> THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 设置值
     *
     * @param id id
     */
    public static void setCurrentId(String id) {
         THREAD_LOCAL.set(id);
    }

    /**
     * 获取值
     *
     * @return Long
     */
    public static String getCurrentId() {
        return THREAD_LOCAL.get();
    }

    /**
     * 删除值
     */
    public static void removeCurrentId() {
        THREAD_LOCAL.remove();
    }
}